import moment from "moment";
export function downloadByBlob(res: any, name: string) {
  const blob = new Blob([res], {
    type: "application/octet-stream",
  });
  const a = document.createElement("a");
  a.setAttribute("href", window.URL.createObjectURL(blob));
  a.setAttribute("download", name);
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
}
export function downloadByURL(url: string, name: string) {
  const a = document.createElement("a");
  a.setAttribute("href", url);
  a.setAttribute("target", "_blank");
  a.setAttribute("download", name);
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
}

export const datetimeFormat = (timestamp: any) => {
  return moment(timestamp).format("YYYY-MM-DD HH:mm:ss");
};

export const dateFormat = (timestamp: any) => {
  return moment(timestamp).format("YYYY-MM-DD");
};
